import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { Cache } from "../../../cache/Cache";
import { ImagesConst } from "../../../resource/ImagesConst";
import { EIntegralShopType } from "../../../../../Message/Public/EIntegralShopType";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ObjCreate } from "../ObjCreate";
import { IntegralShopRecordCellRenderer } from "./IntegralShopRecordCellRenderer";
import { IntegralShopButton } from "./IntegralShopButton";
import { TextBox } from "../../pack/TextBox";
import { MoneyUtil } from "../util/MoneyUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Language } from "../../../../../extend/language/Language";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { ResFileConst } from "../../../resource/ResFileConst";
import { MuiEvent } from "../../../../../com/mui/events/MuiEvent";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SMoney } from "../../../../../Message/Game/SMoney";
import { GTabBar } from "../../../../../com/mui/controls/GTabBar";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class IntegralShopBaseWindow
    
    export  class IntegralShopBaseWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._shopTabData = [];
            setSize(795, 500);
            titleHeight = 53;
            return;
        }

        /* internal  */onLoadedHandler(): void
        {
            this._isLoaded = true;
            if (this._titleBitmap) 
            {
                this._titleBitmap.bitmapData = GlobalClass.getBitmapData(this.getTitleBitmapName());
                this._titleBitmap.x = (795 - this._titleBitmap.width) / 2;
            }
            if (this._tipBitmap) 
            {
                this._tipBitmap.bitmapData = GlobalClass.getBitmapData(this.getTopTipBitmapName());
            }
            if (this._unitBitmap) 
            {
                this._unitBitmap.bitmapData = GlobalClass.getBitmapData(this.getUnitLabelBitmapName());
            }
            if (this._unitIconBitmap) 
            {
                this._unitIconBitmap.bitmapData = GlobalClass.getBitmapData(this.getUnitIconBitmapName());
            }
            if (this._rightTitle) 
            {
                this._rightTitle.bitmapData = GlobalClass.getBitmapData(this.getRightTitleBitmapName());
            }
            return;
        }

        protected updateRecords(arg1: Array<any>): void
        {
            this._recordList.dataProvider = new DataProvider(arg1);
            return;
        }

        protected set integralOptType(arg1: int)
        {
            this._integralOptType = arg1;
            return;
        }

        protected set titleSwf(arg1: string)
        {
            this._titleSwf = arg1;
            LoaderHelp.setBitmapdata(arg1 + ".swf", this._topTitle, -20, -54);
            return;
        }

        protected set shopTabData(arg1: Array<any>)
        {
            this._shopTabData = arg1;
            this._shopTabBar.dataProvider = arg1;
            return;
        }

        protected onTabIndexChange(arg1: int): void
        {
            this.updateMoney(Cache.instance.role.money);
            return;
        }

        protected getTopTipBitmapName(): string
        {
            var loc1=ImagesConst.ISTip0;
            var loc2=this._shopTabBar.selectedIndex;
            if (this._shopType != EIntegralShopType._EIntegralShopOne) 
            {
                if (this._shopType != EIntegralShopType._EIntegralShopTwo) 
                {
                    if (this._shopType == EIntegralShopType._EIntegralShopThree) 
                    {
                        loc1 = ImagesConst.ISTip2;
                    }
                }
                else 
                {
                    loc1 = ImagesConst.ISTip1;
                }
            }
            else 
            {
                loc1 = ImagesConst.ISTip0;
            }
            return loc1;
        }

        protected getTitleBitmapName(): string
        {
            var loc1=ImagesConst.ISTitle0;
            var loc2=this._shopTabBar.selectedIndex;
            if (this._shopType != EIntegralShopType._EIntegralShopOne) 
            {
                if (this._shopType != EIntegralShopType._EIntegralShopTwo) 
                {
                    if (this._shopType == EIntegralShopType._EIntegralShopThree) 
                    {
                        if (this._integralOptType != IntegralShopBaseWindow.BUYSHOP) 
                        {
                            loc1 = ImagesConst.ISExchangeTitle2;
                        }
                        else 
                        {
                            loc1 = ImagesConst.ISTitle2;
                        }
                    }
                }
                else if (this._integralOptType != IntegralShopBaseWindow.BUYSHOP) 
                {
                    loc1 = ImagesConst.ISExchangeTitle1;
                }
                else 
                {
                    loc1 = ImagesConst.ISTitle1;
                }
            }
            else if (this._integralOptType != IntegralShopBaseWindow.BUYSHOP) 
            {
                loc1 = ImagesConst.ISExchangeTitle0;
            }
            else 
            {
                loc1 = ImagesConst.ISTitle0;
            }
            return loc1;
        }

        protected getOpenButtonType(): int
        {
            if (this._integralOptType == IntegralShopBaseWindow.BUYSHOP) 
            {
                return 2;
            }
            return 1;
        }

        protected getUnitLabelBitmapName(): string
        {
            var loc1=ImagesConst.ISUnit0;
            var loc2=this._shopTabBar.selectedIndex;
            if (this._shopType != EIntegralShopType._EIntegralShopOne) 
            {
                if (this._shopType != EIntegralShopType._EIntegralShopTwo) 
                {
                    if (this._shopType == EIntegralShopType._EIntegralShopThree) 
                    {
                        loc1 = ImagesConst.ISUnit2;
                    }
                }
                else 
                {
                    loc1 = ImagesConst.ISUnit1;
                }
            }
            else 
            {
                loc1 = ImagesConst.ISUnit0;
            }
            return loc1;
        }

        protected getUnitIconBitmapName(): string
        {
            var loc1=ImagesConst.ISUnitIcon0;
            var loc2=this._shopTabBar.selectedIndex;
            if (this._shopType != EIntegralShopType._EIntegralShopOne) 
            {
                if (this._shopType != EIntegralShopType._EIntegralShopTwo) 
                {
                    if (this._shopType == EIntegralShopType._EIntegralShopThree) 
                    {
                        loc1 = ImagesConst.ISUnitIcon2;
                    }
                }
                else 
                {
                    loc1 = ImagesConst.ISUnitIcon1;
                }
            }
            else 
            {
                loc1 = ImagesConst.ISUnitIcon0;
            }
            return loc1;
        }

        protected getRightTitleBitmapName(): string
        {
            var loc1=ImagesConst.ISLogTitle;
            var loc2=this._shopTabBar.selectedIndex;
            if (this._integralOptType != IntegralShopBaseWindow.BUYSHOP) 
            {
                loc1 = ImagesConst.ISLogTitle;
            }
            else if (loc2 == 0 || loc2 == 1 || loc2 == 2) 
            {
                loc1 = "ISExchangeShowTitle" + loc2;
            }
            return loc1;
        }

        protected onOpenButtonClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            addChild(new GImageBitmap(ImagesConst.IntegralShopGirl, -250, 0));
            this._topTitle = new Object /* flash.display.Bitmap */();
            title = this._topTitle;
            LoaderHelp.setBitmapdata(ImagesConst.IntegralShopTitle + ".swf", this._topTitle, -20, -54);
            this._titleBitmap = new Object /* flash.display.Bitmap */();
            this._titleBitmap.x = 0;
            this._titleBitmap.y = -15;
            this.addChild(this._titleBitmap);
            this._shopTabBar = ObjCreate.createGTabBar(16, 38, [], 80, 22, this, this.onShopTabBarChangeHandler);
            this._tipBitmap = new Object /* flash.display.Bitmap */();
            this._tipBitmap.x = 280;
            this._tipBitmap.y = 40;
            this.addChild(this._tipBitmap);
            this._rightPanel = new Object /* flash.display.Sprite */();
            this._rightPanel.x = 550;
            this._rightPanel.y = 65;
            this.addChild(this._rightPanel);
            ObjCreate.createBg(0, 0, 225, 422, this._rightPanel);
            this._recordList = ObjCreate.createTileList(5, 28, 220, 260, this._rightPanel);
            this._recordList.columnWidth = 220;
            this._recordList.rowHeight = 40;
            this._recordList.setStyle("cellRenderer", IntegralShopRecordCellRenderer);
            ObjCreate.createBg(550, 63, 227, 25, this, ImagesConst.RbListHeader);
            this._rightTitle = new Object /* flash.display.Bitmap */();
            this._rightTitle.x = 590;
            this._rightTitle.y = 65;
            addChild(this._rightTitle);
            this._openBtn = new IntegralShopButton(this.getOpenButtonType());
            this._openBtn.x = 90;
            this._openBtn.y = 340;
            this._openBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOpenButtonClickHandler);
            this._rightPanel.addChild(this._openBtn);
            this._unitBitmap = new Object /* flash.display.Bitmap */();
            this._unitBitmap.x = 8;
            this._unitBitmap.y = 395;
            this._rightPanel.addChild(this._unitBitmap);
            this._unitIconBitmap = new Object /* flash.display.Bitmap */();
            this._unitIconBitmap.x = 90;
            this._unitIconBitmap.y = 393;
            this._rightPanel.addChild(this._unitIconBitmap);
            this._unitTextBox = new TextBox();
            this._unitTextBox.textFieldHeight = 20;
            this._unitTextBox.textFieldWidth = 85;
            this._unitTextBox.bgHeight = 20;
            this._unitTextBox.bgWidth = 85;
            this._unitTextBox.x = 115;
            this._unitTextBox.y = 393;
            this._unitTextBox.htmlText = MoneyUtil.getGoldHtml(521035);
            this._rightPanel.addChild(this._unitTextBox);
            this._bottomPanel = new Object /* flash.display.Sprite */();
            this._bottomPanel.x = 18;
            this._bottomPanel.y = 402;
            this.addChild(this._bottomPanel);
            ObjCreate.createBg(0, 0, 527, 45, this._bottomPanel);
            ObjCreate.createBg(0, 50, 527, 35, this._bottomPanel);
            var loc1=15;
            ObjCreate.createBitmap(ImagesConst.Yuanbao, 325, loc1 + 2, this._bottomPanel);
            this._goldTxt = ObjCreate.createGTextField("", 350, loc1, 60, 20, this._bottomPanel, GlobalStyle.textFormat6);
            this._goldTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._rechargeBtn = ObjCreate.createGButton(Language.getString(53005), 440, 10, 80, 25, this._bottomPanel, "ButtonRed");
            this._rechargeBtn.drawNow();
            (this._rechargeBtn.getChildAt(1) as Object /* flash.text.TextField */).filters = [FilterConst.nameGlowFilter];
            this._rechargeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onRechargeBtnClick);
            LoaderHelp.addResCallBack(ResFileConst.IntegralShop, this.onLoadedHandler);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            _isCenter = true;
            super.show(arg1, arg2);
            this.updateMoney(Cache.instance.role.money);
            return;
        }

        /* internal  */onShopTabBarChangeHandler(arg1: MuiEvent): void
        {
            var loc1=arg1.target.selectedIndex;
            this.onTabIndexChange(loc1);
            if (this._isLoaded) 
            {
                this.onLoadedHandler();
            }
            return;
        }

        /* internal  */onRechargeBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GotoPay));
            return;
        }

        public updateMoney(arg1: SMoney): void
        {
            if (this._goldTxt) 
            {
                this._goldTxt.htmlText = MoneyUtil.getGoldHtml(arg1.gold);
            }
            if (this._unitTextBox) 
            {
                if (this._shopType != EIntegralShopType._EIntegralShopOne) 
                {
                    if (this._shopType != EIntegralShopType._EIntegralShopTwo) 
                    {
                        if (this._shopType == EIntegralShopType._EIntegralShopThree) 
                        {
                            this._unitTextBox.htmlText = MoneyUtil.getGoldHtml(arg1.integralThree);
                        }
                    }
                    else 
                    {
                        this._unitTextBox.htmlText = MoneyUtil.getGoldHtml(arg1.integralTwo);
                    }
                }
                else 
                {
                    this._unitTextBox.htmlText = MoneyUtil.getGoldHtml(arg1.integralOne);
                }
            }
            LoaderHelp.addResCallBack(ResFileConst.IntegralShop, this.onLoadedHandler);
            return;
        }

        public static /* const */BUYSHOP: int=1;

        public static /* const */EXCHANGESHOP: int=2;

        protected /* var */_shopType: int=1;

        /* internal */ /* var */_topTitle: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_titleBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tipBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_rightTitle: Object /* flash.display.Bitmap */;

        protected /* var */_shopTabBar: GTabBar;

        protected /* var */_rightPanel: Object /* flash.display.Sprite */;

        protected /* var */_recordList: GTileList;

        /* internal */ /* var */_openBtn: IntegralShopButton;

        protected /* var */_unitBitmap: Object /* flash.display.Bitmap */;

        protected /* var */_unitIconBitmap: Object /* flash.display.Bitmap */;

        protected /* var */_unitTextBox: TextBox;

        protected /* var */_bottomPanel: Object /* flash.display.Sprite */;

        protected /* var */_goldTxt: GTextFiled;

        /* internal */ /* var */_rechargeBtn: GButton;

        /* internal */ /* var */_integralOptType: int=2;

        /* internal */ /* var */_titleSwf: string;

        protected /* var */_shopTabData: Array<any>;

        /* internal */ /* var */_isLoaded: Boolean;
    }
